<?php
/**
 * Created by PhpStorm.
 * User: prg
 * Date: 2017/3/9
 * Time: 16:47
 */

//查看新闻的详情接口，根据传入的id来获取具体的新闻内容

require_once 'response.php';
require_once 'db.php';

header('content-type:text/html;charset:utf-8');
header('Access-Control-Allow-Origin:*');
header('Access-Control-Allow-Methods:GET');
header('Access-Control-Allow-Headers:x-requested-with,content-type');

$id = isset($_GET['newsId'])? $_GET['newsId'] : '';

if(!is_numeric($id)) {
    return Response::show(401,'数据不合法');
}

try{
    $connect = Db::getInstance()->connect();
} catch (Exception $e) {
    return Response::show(403,'数据库连接失败',$e->getMessage());
}

$sql = "SELECT news_title,news_content,news_time,news_maker FROM news WHERE news_id={$id}";
$res = $connect->query($sql);

$data = array();

if($res && $res->num_rows>0) {
    while($info = $res->fetch_assoc()) {
        $data = $info;
    }
    return Response::show(200,'新闻获取成功',$data);
} else {
    return Response::show(404,'获取新闻失败');
}

